import { sierpinskiPoints } from '../algorithm/sierpinski.js'
import { _polar } from '../math/index.js'
import { _path2 } from './path2.js'
import { polarPoints } from "../algorithm/polar.js";
import { _traversal } from '../algorithm/traversal.js'
import { _bezierCurveTo, _moveTo } from './curve.js'
import { _path } from './svg.js'

export const _sierpinski = (options, props) => {
    let points = polarPoints(options)
    let { depth = 0, skew = 0, amplitude = 0, loop = true, bottomControlGear } = options

    // 
    let ps = sierpinskiPoints({
        points, depth, skew, amplitude, loop, bottomControlGear
    })
    return _path2({
        ...options,
        points: ps,
    }, props)
}

// 杨辉三角贝塞尔
export const _sierpinskiBezier = (options, props) => {
    let points = polarPoints(options)
    let { depth = 0, skew = 0, amplitude = 0, loop = true, bottomControlGear } = options
    let ps = sierpinskiPoints({ points, depth, loop, bottomControlGear, amplitude })
    let n = 4
    let path = _traversal({
        points: ps,
        n,
        iter: ([p1, p2, p3, p4]) => {
            return _bezierCurveTo([p2, p3, p4])
        },
        init: _moveTo,
        loop
    }
    ).join(' ')

    return _path(path, {
        stroke: 'red',
        fill: 'none',
        ...props
    })

}